﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Security.Cryptography;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using CoreShop.App;
using CoreShop.Library;
using CoreShop.Services;
using System.Windows.Forms;
using CoreShop.Model;
using CoreShop.PrintService;
using SqlSugar;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
using Yitter.IdGenerator;
using SqlSugar.Extensions;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Sunny.UI;
using System.Xml;
using NPOI.SS.Formula.Functions;
using NPOI.Util;
using CoreShop.Model.UI;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using static System.Windows.Forms.AxHost;
using Sunny.UI.Win32;
using IWshRuntimeLibrary;
using FastMember;
using PluSoft.Utils;
using System.Threading.Tasks;
using CoreShop.Model.FromBody;
using Org.BouncyCastle.Asn1.Tsp;
using System.Threading;
using CoreShop.App.Units.Interface;

namespace CoreShop.App
{
    public class SyncUtil
    {
        /// <summary>
        /// 静态初始化数据
        /// </summary>
        public struct RecordTableName
        {
            /// <summary>
            /// 1、商城订单
            /// </summary>
            public static string MallOrder = "xcx_order_head";
            /// <summary>
            /// 2、商品分类
            /// </summary>
            public static string GoodCategory = "---";
            /// <summary>
            /// 3、商品资料
            /// </summary>
            public static string GoodData = "---";
            /// <summary>
            /// 4、促销活动
            /// </summary>
            public static string Activity = "---";
            /// <summary>
            /// 5、商品调价
            /// </summary>
            public static string GoodChgPrice = "---";
            /// <summary>
            /// 6、副屏广告
            /// </summary>
            public static string ScreemImg = "---";
            /// <summary>
            /// 7、商品单位
            /// </summary>
            public static string GoodUnit = "---";
            /// <summary>
            /// 7、前台参数设置
            /// </summary>
            public static string PosPara = "---";
            /// <summary>
            /// 8、用户权限
            /// </summary>
            public static string UserRouters = "---";
            /// <summary>
            /// 9、营业员资料
            /// </summary>
            public static string Employee = "---";
            /// <summary>
            /// 10、下载收款方式
            /// </summary>
            public static string BalanceType = "---";
        }


        public List<sysrecordentity> GetSysRecordEntity(sysuser sysuser, ref string msg)
        {
            try
            {
                var sysRecordEntity = new PosRemoteServices().GetSysRecordEntity(sysuser, ref msg);
                //查到本地时间与服务器时间不同的数据
                if ((sysRecordEntity != null) && (sysRecordEntity.Count > 0))
                {
                    var sysrecordentitySvr = new sysrecordentityServices();
                    var thisRecordList = sysrecordentitySvr.AsQueryable().Where(p => p.tenantId == sysuser.corpId).ToList();
                    foreach (var item in sysRecordEntity)
                    {
                        item.thisRecordTime = item.recordTime;//先给相等的值
                        var thisRecordData = thisRecordList.Find(p => p.recordName == item.recordName);
                        if (thisRecordData != null)
                            item.thisRecordTime = thisRecordData.recordTime;
                    }
                    sysrecordentitySvr.InsertOrUpdateAsync(sysRecordEntity);
                }
                return sysRecordEntity;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return null;
            }
        }        
    }
}
